/*
 * ConnectionThread.java
 *
 * Created on June 6, 2007, 9:05 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.bloomingstars.bluepad;

import com.bloomingstars.bluepad.comm.CommType;
import com.bloomingstars.bluepad.comm.CommandCode;
import com.bloomingstars.bluepad.comm.DA2Address;
import com.bloomingstars.bluepad.comm.DA2Comm;
import com.bloomingstars.bluepad.comm.DA2CommFactory;
import com.bloomingstars.bluepad.comm.DA2CommListener;

/**
 *
 * @author toni
 */
public class ConnectionThread implements Runnable
{
    private DA2Comm comm;
    
    public DA2Comm connection()
    {
        return comm;
    }
    
    public void run()
    {
        comm = DA2CommFactory.createDA2Comm(CommType.BLUETOOTH);
        DA2Address address = new DA2Address("", "da2");
        
        int setupStatus = comm.setup(address);
        
        comm.addCommListener(new DA2CommListener()
        {
            public void dataReceived(String s, int cmd)
            {
                System.out.println("Listener - Data received: " + s + " " + cmd);
            }
            
            public void connectionLost()
            {
                System.out.println("Connection lost!");
            }
        });
        
        System.out.println("Setup status: " + setupStatus);
        
        comm.connect();        
    }
}
